#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include "studentManager.h"

using namespace std;

static void showMenu() 
{
    myprint("              欢迎登录！\n");
    myprint("╔═══════════════════════════════════════════════╗\n");
    myprint("║                学生管理系统                   ║\n");
    myprint("╠═══════════════════════════════════════════════╣\n");
    myprint("║                                               ║\n");
    myprint("║            1.添加学生信息                     ║\n");
    myprint("║                                               ║\n");
    myprint("║            2.查询学生信息                     ║\n");
    myprint("║                                               ║\n");
    myprint("║            3.显示所有学生                     ║\n");
    myprint("║                                               ║\n");
    myprint("║            4.编辑学生信息                     ║\n");
    myprint("║                                               ║\n");
    myprint("║            5.删除学生信息                     ║\n");
    myprint("║                                               ║\n");
    myprint("║            6.统计学生信息                     ║\n");
    myprint("║                                               ║\n");
    myprint("║            7.保存到文件                       ║\n");
    myprint("║                                               ║\n");
    myprint("║            8.从文件读取                       ║\n");
    myprint("║                                               ║\n");
    myprint("║            9.成绩排序                         ║\n");
    myprint("║                                               ║\n");
    myprint("║            0.退出当前系统                     ║\n");
    myprint("║                                               ║\n");
    myprint("╚═══════════════════════════════════════════════╝\n\n");
    myprint("请选择您的操作： ");
}

int main() {
#ifdef _WIN32
    system("chcp 65001 > nul"); // 切换到 UTF-8
#endif

    StudentManager manager;
    int choice;

    // 启动时自动从文件加载数据
    manager.loadFromFile();

    while (true) {
        showMenu();
        cin >> choice;
        cin.ignore(numeric_limits<streamsize>::max(), '\n');

        switch (choice) {
            case 1:
                manager.addStudent();
                break;
            case 2:
                manager.queryStudent();
                break;
            case 3:
                manager.displayAll();
                break;
            case 4:
                manager.editStudent();
                break;
            case 5:
                manager.deleteStudent();
                break;
            case 6:
                manager.statistics();
                break;
            case 7:
                manager.saveToFile();
                break;
            case 8:
                manager.loadFromFile();
                break;
            case 9:
                manager.sortStudents();
                break;
            case 0:
                myprint("    感谢使用，再见！： ");
                cout << "" << endl;
                return 0;
            default:
                myprint("    无效的选择，请重试！： ");
                cout << "" << endl;
                break;
        }
    }
    return 0;
}